$(document).ready(function (){

    var val = document.getElementById("pur-num1");
    $("#yes1").click(function(){
        val.removeAttribute("disabled");
        console.log(val);
    });
    $("#no1").click(function(){
        val.setAttribute("disabled", "true");
        console.log(val);
    });


    // 查看详情
    // 这一部分应该还需要把修改的商品写到页面上——————！
    $(".modal").hide();
    $(".product-info").hide();//调试需要暂时不隐藏
    $('table').on('click','.btn-look',function() {
    // $(".btn-look").click(function(){
        $("#modal-dely").css("display", "table");

        var td = this.parentNode;        //先从删除按钮取到的父节点   向上取到td
        var tr = td.parentNode;          //再取td的父节点     向上取到tr，也就是定位到这一行
        var id = tr.children[0].innerText;
        console.log(id);
        document.getElementById("id1").innerText = id;
                            
        $.ajax({
            url: "http://8.130.103.251:8080/good/getGood",    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true, //请求是否异步，默认为异步，这也是ajax重要特性
            data: {
                    goodid: id//  "id": "value"
            },    //参数值
           type: "GET",   //请求方式
          
           success: function(good) {
            console.log(good);
            console.log(good.goodBrand);

            $("#sale").html(good.buyTime);

            $("#image").attr("src", good.goodImg1);
            $("#image0").attr("src", good.goodImg2);
            $("#image1").attr("src", good.goodImg3);

            $("#name-val1").val(good.goodName);
            $("#num-num1").val(good.goodNum);
            $("#pur-num1").val(good.goodPrice);
            $("#rent-num0").val(good.dayPrice);
            $("#rent-num1").val(good.monthPrice);

            // $("#tag-num1 option[value='1']").prop("selected", true);  //设置value值为1的选项被选中

            // 选中tag下拉框中正确的选项
            var optnum =  $('#tag-num1 option').length;
            for(var n = 0; n < optnum; n++){
                var text = $("#tag-num1 option:eq(" + n + ")").text();
                if(text == good.goodType)
                {
                    $("#tag-num1").val(n);
                    var opt1=$("#tag-num1 option:selected");  //获取选中的option
                    var tag1 = opt1.text();   //拿到选中项的文本,比如选中上海，获取的值为“上海”
                    console.log(tag1);
                    console.log(good.goodBrand);
                    var data1 = {
                        type: tag1
                    }	
                    $.ajax({
                        url:'http://8.130.103.251:8080/good/getBrandByType',	//这是后端接口的url
                        dataType: "json",   //返回格式为json
                        ContentType: 'application/json;charset=utf-8', //传输格式
                        data:data1,
                        type: "GET",
                        async: false,
                        success:function (req) {
                            $("#tag-num11").empty();
                            for(var l = 0; l < req.length; l++)
                            {
                                var opt = '<option value="' + l + '">' + req[l] + '</option>';
                                $("#tag-num11").append(opt);
                            }
                            var optnum1 =  $('#tag-num11 option').length;
                            for(var n = 0; n < optnum1; n++){
                                var text1 = $("#tag-num11 option:eq(" + n + ")").text();
                                if(text1 == good.goodBrand)
                                {
                                    // console.log(good.goodBrand);
                                    $("#tag-num11").val(n);
                                    break;
                                }
                            }
                            
                        },
                    });
                    break;
                }
            }

                
              

            $("#des-txt1").val(good.goodInfo);
            if(good.buyStatus)
            {
                $("#yes1").prop("checked", "checked");
            }
            else
            {
                $("#no1").prop("checked", "checked");
            }

           },
        
        
        });
        
        $(".modal").show();
        // $(".product-info").show();
        $(".product-info").fadeIn(200);

    })
    
    
    });